<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/30 0030
 * Time: 15:07
 */
//配置文件封装
//第一件套
session_start();



function mylink(){
//    $host = '127.0.0.1';
    $host = '60.205.213.189';
    $name = 'root';
    $pass = 'caowen83760250';
    $database = 'php200';
    $link = mysqli_connect($host,$name,$pass,$database);
    if($link){
        return $link;
    }else{
        return mysqli_connect_error();
    }
}
//查询封装
/**
 * @param $sql
 * @return array
 */
//多个数据查询
function query($sql){
    $links = mylink();
    $res = mysqli_query($links,$sql);
//    mysqli_set_charset($links, "utf8");
    $arr = [];
    while($data = mysqli_fetch_assoc($res)){
        $arr[] = $data;
    }
    return $arr;
}
//只查询一个数据
function find($sql){
    $links = mylink();
//    mysqli_set_charset($links, "utf8");
    $res = mysqli_query($links,$sql);
    $data = mysqli_fetch_assoc($res);
    return $data;
}
/**
 * @param $sql
 * @return bool|mysqli_result
 */
//新增封装  修改  删除
function insert($sql){
    $links = mylink();
    $res = mysqli_query($links,$sql);
    return $res;
}


